import java.util.*;
public class Intersection { 
  public double[] intersection(int[] start1, int[] end1, int[] start2, int[] end2) {
        double x1 = start1[0], y1 = start1[1], x2 = end1[0], y2 = end1[1];
        double x3 = start2[0], y3 = start2[1], x4 = end2[0], y4 = end2[1];
        double[] res = new double[2]; 
        double a1 = y2 - y1, b1 = x1 - x2, c1 = x2 * y1 - x1 * y2;
        double a2 = y4 - y3, b2 = x3 - x4, c2 = x4 * y3 - x3 * y4;
        double d = a1 * b2 - a2 * b1; // 斜率
        if(d == 0){
            if(c1!= c2){
                return new double[0]; // 无交点
            } else {
                double minX = Math.min(Math.min(x1, x2), Math.min(x3, x4));
                double minnY = Double.MAX_VALUE;
                double[] ys = new double[]{y1, y2, y3, y4};
                for(int i = 0; i < 4; i++){
                if(ys[i] < minnY ){
                    minnY = ys[i];
                }
                return new double[]{minX, minnY}; // 重合
                }
            }
            
            
        }
        res[0] = (b1 * c2 - b2 * c1) / d;
        res[1] = (a2 * c1 - a1 * c2) / d;
        return res;
    }
}

// 给定两条线段（表示为起点start = {X1, Y1}和终点end = {X2, Y2}），如果它们有交点，请计算其交点，没有交点则返回空值。

// 要求浮点型误差不超过10^-6。若有多个交点（线段重叠）则返回 X 值最小的点，X 坐标相同则返回 Y 值最小的点。